package com.auemall.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.auemall.constant.ApplicationConstant;
import com.auemall.service.UserService;
import com.auemall.vo.BaseRespVO;
import com.auemall.vo.UserVO;


/**
 * 用户管理Controller
 * <p>Title: UserController</p>
 * <p>Description: </p>
 *
 */

@Controller
@RequestMapping("/user/v1")
public class UserController {
    
    private Logger logger = Logger.getLogger(UserController.class);

	@Autowired
	private UserService userService;
	
	
	/**
	 * 
	 * @Title: addUser 
	 * @Description: TODO(添加用户)
	 * @param req
	 * @return BaseRespVO  
	 * @author wuyue
	 */
	@RequestMapping(value="/adduser", method=RequestMethod.POST)
    @ResponseBody
    public BaseRespVO addUser(@RequestBody UserVO req) {
        BaseRespVO respVO;
        try{
            respVO = userService.addUser(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("添加用户信息异常（/user/v1/adduser）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
	
	
	@RequestMapping(value="/updateuser", method=RequestMethod.POST)
	@ResponseBody
	private BaseRespVO updateUser(@RequestBody UserVO req) {
	    BaseRespVO respVO;
	    try{
	        respVO = userService.updateUser(req);
	    }catch(Exception e){
	        respVO = new BaseRespVO();
	        respVO.setResult(ApplicationConstant.RESULT_FALTURE);
	        respVO.setMsg("修改商品品牌异常（/item/v1/updateitembrand）："+e.getMessage());
	        logger.error(respVO.getMsg());
	    }
	    return respVO;
	}
	
	/**
	 * 
	 * @Title: deleteItemBrand 
	 * @Description: TODO(删除商品品牌)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/deleteuser")
	@ResponseBody
	private BaseRespVO deleteUser(@RequestBody UserVO req) {
	    BaseRespVO respVO;
	    try{
	        respVO = userService.deleteUser(req);
	    }catch(Exception e){
	        respVO = new BaseRespVO();
	        respVO.setResult(ApplicationConstant.RESULT_FALTURE);
	        respVO.setMsg("删除商品品牌异常（/item/v1/deleteitembrand）："+e.getMessage());
	        logger.error(respVO.getMsg());
	    }
	    return respVO;
	}
}
